{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 一元线性回归\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x = [[1],[2],[3],[4],[5],[6]]\n",
    "y = [[1],[2.1],[2.9],[4.2],[5.1],[5.8]] # y = ax + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'y = 0.980x + 0.087'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = LinearRegression()\n",
    "model.fit(x, y)\n",
    "'y = %.3fx + %.3f' % (model.coef_[0], model.intercept_[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 12.82666667]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predicted = model.predict(13) # 或者输入[[13]]\n",
    "predicted"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x = [[1],[2],[3],[4],[5],[6]]\n",
    "y = [[1],[2.1],[2.9],[4.2],[5.1],[5.8]]\n",
    "model = LinearRegression()\n",
    "model.fit(x, y)\n",
    "x2 = [[0], [2.5], [5.3], [9.1]]\n",
    "y2 = model.predict(x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x21a34d9c780>]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAHc9JREFUeJzt3Xl4lPW9/vH3BzQgAgWU1gUVFE2r\nVGSxEumpQ9lcemoXe5TF9ZTYKotWQdS6tXWriPXXVpYKWiVicTsCAorBqFTccGMz4sZWBGQVJQlJ\nPr8/MkxiDJAhyXxnuV/XxUUy6yfPlcmd55k738fcHREREYBGoQcQEZHkoVAQEZEYhYKIiMQoFERE\nJEahICIiMQoFERGJUShIUjOzT82sT/Tj68zs/tAzJQszu9nMpoSeQ9LLfqEHEKktd78t9Awi6U57\nCiJ7YWaNQ88gkigKBUkZVQ+XmFl7M3Mzu9DMVprZ52Z2fZXbNjKz0Wb2kZltNLNpZtamyvWPmdln\nZrbVzF4ysxOqXPegmY0zs1lm9iXQq4ZZLjKzj83sCzP7xMwGRS8/xszmRZ/zczPLM7NWVe73qZmN\nNLP3zOxLM5tkZt8xs9nRx3rezFpX+xpzzew/ZrbWzK7aw/bpYWavmNkWM3vXzCJ12+KSiRQKkup+\nCGQDvYEbzex70cuHAz8DTgMOAzYDf69yv9nAscC3gbeAvGqPOxC4FWgBzK96hZkdCPw/4Ax3bwGc\nCryz62rg9uhzfg84Ari52mP/EugLHAf8d3SW64CDqXhNDq92+17RWfsBo3e9x1JtpsOBZ4A/AW2A\nq4EnzKxt9duK7IlCQVLdLe6+w93fBd4FOkcvvxS43t1Xu3sxFT+YzzGz/QDcfbK7f1Hlus5m9q0q\nj/u0u//b3cvdvaiG5y0HOpnZAe6+1t2XRB/3Q3ef6+7F7r4BGEtFMFX1V3df5+5rgJeB19z97egs\nTwFdavgav3T3RcAD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3KmlDgX1YDiNduftad38r+vEXVLzwDw87VThm1g44C7g/9Cwh\nmVlL4EfAJAB3L3H3LWGnCmo/4AAz2w9oRgb9/ZO7vwRsqnbx2cA/ox//E/hZbR4rmUOhpuUwMvYH\n4S5m1h7oArwWdpKg/gKMAspDDxLY0cAG4IHoobT7zezA0EOF4O5rgDHASmAtsNXdnws7VXDfcfe1\nUPGLJVCrcxUncyjUajmMTGJmzYEngCvcfVvoeUIws58A6919YehZksB+QFdgnLt3Ab6klocI0k30\nePnZQAfgMOBAMxscdqrUlMyhoOUwqjCz/akIhDx3fzL0PAH1BH5qZp9ScUjxx2Y2JexIwawGVrv7\nrr3Gx6kIiUzUB/jE3Te4+07gSeDUwDOFts7MDgWI/r++NndK5lDQchhRVrFu+CRgmbuPDT1PSO5+\nrbu3c/f2VHxPzHP3jPyN0N0/A1aZ2a6VMHsDuz0vSZpbCfQws2bR10tvMvRN9yqmAxdGP74QeLo2\nd0ra03Hu43IY6aoncD6wyMzeiV52nbvPCjiTJIdhQF70F6ePgYsDzxOEu79mZo8Db1HR1nubDFru\nwsymAhHgYDNbDdwE3AFMM7P/pSI0f1Wrx9IyFyIisksyHz4SEZEEUyiIiEiMQkFERGIUCiIiEqNQ\nEBGRGIWCiIjEKBRERCRGoSCyD8zsZDN7z8yamtmB0XX8O4WeS6Su9MdrIvvIzP4ENAUOoGINotsD\njyRSZwoFkX0UXVriDaAIONXdywKPJFJnOnwksu/aAM2BFlTsMYikPO0piOwjM5tOxfLdHYBD3X1o\n4JFE6ixpV0kVSWZmdgFQ6u6PRM8n/oqZ/djd54WeTaQutKcgIiIxek9BRERiFAoiIhKjUBARkRiF\ngoiIxCgUREQkRqEgIiIxCgUREYn5/8M0lSHIodvAAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x21a34c080b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.title('linear sample')\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.axis([0, 10, 0, 10])\n",
    "plt.grid(True)\n",
    "plt.plot(x, y, 'k.')\n",
    "plt.plot(x2, y2, 'g-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.var([1,2,3,4,5,6], ddof=1) # 计算方差，ddof是无偏估计校正技术。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 3.5       ,  3.43      ],\n",
       "       [ 3.43      ,  3.38166667]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cov([1,2,3,4,5,6], [1,2.1,2.9,4.2,5.1,5.8]) # 计算协方差\n",
    "# 对角线元素是每个元素的方差\n",
    "# 非对角线元素是2个数组的协方差"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
